<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录界面</title>
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script>
        $(function(){
            $("#login").on("click",function(){
                var username = $("#username").val();
                var password = $("#password").val();
                var code = $("#code").val();

                $.ajax({
                    url:"/PermissionSystem/account/login",
                    type:"get",
                    data:{
                        username:username,
                        password:password
                    },
                    dataType:"json",
                    success:function(data){
                        console.log(data);
                        console.log(data.code);
                        if(data.code == 200){
                            window.location.href="http://localhost:8080/PermissionSystem/html/content.html"
                            $.cookie("username",username);
                        }else{
                            alert(data.message);

                        }



                    }
                })
            })

            //定义发送验证码的函数
            function sendMail(){
                //获取账号框中的值
                let account = $("#account").val().trim();
                //获取邮箱框中的值
                let mail = $("#mail").val().trim();
                let flag;
                //非空校验
                if(account == ""){
                    alert("账号不能为空");
                    //账号文本框获得焦点
                    $("#account").focus();
                    flag = false;
                    return flag;
                }
                if(mail == ""){
                    alert("邮箱不能为空");
                    //邮箱文本框获得焦点
                    $("#mail").focus();
                    flag = false;
                    return flag;
                }
                flag = true;
                if(flag){
                    $.ajax({
                        url:"/PermissionSystem/account/sendMail",
                        type:"get",
                        data:{
                            account:account,
                            mail:mail
                        },
                        dataType: "json",
                        success:function (data){
                            console.log(data)
                            //用cookie把验证码存起来
                            $.cookie("verify",data.captcha);
                        }
                    })
                }
            }

            //点击发送验证码按钮发送邮件
            $("#send").on("click",function (){
                sendMail();
            })

            $("#register").on("click",function(){
                window.location.href="http://localhost:8080/PermissionSystem/html/register.html"
            })







            })
    </script>
</head>
<body>
    <div class="whole">
        <div class="head">
            权限系统登录
        </div>
        <div class="main">
            <div class="item">
                <span>账号</span>
                <input type="text" id="username" placeholder="请填写账号">
            </div>
            <div class="item">
                <span>密码</span>
                <input type="text" id="password" placeholder="请填写密码">
            </div>
            <div class="item1">
                <!--<span>输入验证码</span>-->
                <input type="text" id="email" placeholder="请填写验证码">
                <input type="button" id="send" value="发送验证码">
            </div>
            <div class="item">
                <input type="button" id="login" value="登录">
                <input type="button" id="register" value="注册">

            </div>
        </div>
    </div>

</body>
</html>